package net.tuanhiep1232.medicine.client.custom;

import com.google.gwt.core.client.GWT;
import com.google.gwt.dom.client.Style.Unit;
import com.google.gwt.event.logical.shared.AttachEvent;
import com.google.gwt.event.logical.shared.HasAttachHandlers;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.user.client.ui.Anchor;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.DockPanel;
import com.google.gwt.user.client.ui.HTMLPanel;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.Widget;
import com.sencha.gxt.widget.core.client.container.BorderLayoutContainer;
import com.sencha.gxt.widget.core.client.container.BorderLayoutContainer.BorderLayoutData;

public class RibbonMenuButton extends Composite{

	private static RibbonMenuButtonUiBinder uiBinder = GWT
			.create(RibbonMenuButtonUiBinder.class);

	interface RibbonMenuButtonUiBinder extends
			UiBinder<Widget, RibbonMenuButton> {
	}

	public RibbonMenuButton(String text,String color) {
		initWidget(uiBinder.createAndBindUi(this));
		this.setColor(color);
		this.txt.setText(text);
		this.addAttachHandler(new AttachEvent.Handler() {
			@Override
			public void onAttachOrDetach(AttachEvent arg0) {
				txt.getElement().getStyle().setMarginTop(pn.getOffsetHeight() - txt.getOffsetHeight(), Unit.PX);
			}
		});
	}
	private String color="blue";
	private boolean selected = false;
	
	@UiField(provided = true)
	BorderLayoutData southData = new BorderLayoutData(100);
	
	@UiField
	protected HTMLPanel pn;
//	protected BorderLayoutContainer pn;
	@UiField
	protected Label txt;
	public String getColor() {
		return color;
	}
	public void setColor(String color) {
		this.color = color;
	}
	public Label getTxt() {
		return txt;
	}
	public void setTxt(Label txt) {
		this.txt = txt;
	}
	public String getText(){
		return this.txt.getText();
	}
	public boolean isSelected() {
		return selected;
	}
	public void setSelected(boolean selected) {
		this.selected = selected;
		if(selected) 
			pn.getElement().getStyle().setBackgroundColor(color);
		else 
			pn.getElement().getStyle().setBackgroundColor("none");
	}
}
